package com.example.server.util;

import com.example.server.entity.CartItem;
import org.modelmapper.ModelMapper;
import org.springframework.stereotype.Component;

import java.util.List;
import java.util.stream.Collectors;

@Component
public class Converter<S,D> {

    private ModelMapper modelMapper;

    public Converter(ModelMapper modelMapper) {
        this.modelMapper = modelMapper;
    }

    public D convert(S s,Class<D> dClass){
        return modelMapper.map(s,dClass);
    }

    public List<D> convert(List<S> list,Class<D> dClass){
        return list
                .stream()
                .map(entity -> modelMapper.map(entity,dClass))
                .collect(Collectors.toList());
    }
}
